/*
 * Copyright (c) Tan Menglong.
 * All rights reserved.
 * 
 * This file is part of the RabbitOS.  The RabbitOS is free software, also known
 * as "open source;" you can redistribute it and/or modify it under the terms
 * of the GNU General Public License (GPL), version 2, as published by the Free
 * Software Foundation (FSF).  To explore alternate licensing terms, contact
 * the Tan Menglong at TanMenglong@gmail.com or +86-15972108715.
 * 
 * The RabbitOS is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have
 * received a copy of the GPL along with the RabbitOS; see the file COPYING.  If
 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
 */
/*
 * String functions.
 * 03-May-08
 */

#include "../include/rabbit/string.h"

void memcpy(char *dest, const char *src, int len)
{
	const char *sp = (const char *) src;
	char *dp = (char *) dest;
	for (; len != 0; len--)
		*dp++ = *sp++;
}

void memset(char *dest, char val, int len)
{
	char *temp = (char *) dest;
	for (; len != 0; len--)
		*temp++ = val;
}

int strcmp(char *str1, char *str2)
{
	int i = 0;
	int failed = 0;
	while (str1[i] != '\0' && str2[i] != '\0') {
		if (str1[i] != str2[i]) {
			failed = 1;
			break;
		}
		i++;
	}

	if ((str1[i] == '\0' && str2[i] != '\0')
		|| (str1[i] != '\0' && str2[i] == '\0'))
		failed = 1;

	return failed;
}

char *strcpy(char *dest, const char *src)
{
	do {
		*dest++ = *src++;
	} while (*src != 0);
}

char *strcat(char *dest, const char *src)
{
	while (*dest != 0) {
		*dest = *dest++;
	}

	do {
		*dest++ = *src++;
	} while (*src != 0);

	return dest;
}

int strlen(char *src)
{
	int i = 0;
	while (*src++)
		i++;
	return i;
}
